import java.util.PriorityQueue;

/**
 * @author LKQ
 * @date 2022/3/30 19:52
 * @description 思路：采用优先队列，大顶堆维护k个最小的数，超出内存
 * 原因：m, n, k较大时，线性遍历超时，此时就需要二分来了
 */
public class Solution {
    public static void main(String[] args) {
        Solution solution = new Solution();
        int n = solution.findKthNumber(2,3,6);
        System.out.println(n);
    }
    public int findKthNumber(int m, int n, int k) {
        PriorityQueue<Integer> pq = new PriorityQueue<>((a, b)-> {
            return b - a;
        });
        for (int i = 1; i <= m; i++) {
            for (int j = 1; j <= n; j++) {
                int ans = i * j;
                if ((i-1) * n + j <= k) {
                    pq.add(ans);
                }else {
                    if (ans < pq.peek()) {
                        pq.poll();
                        pq.add(ans);
                    }
                }
            }
        }
        return pq.peek();
    }
}
